
package BusinessAlive;

public class BusinessAlive extends Thread {

    String name;
    Thread objTh;

    public BusinessAlive(String str) {
        name = str;
        objTh = new Thread(this, name);
        System.out.println("New task are starting"+objTh);
        objTh.start();
    }

    @Override
    public void run(){
       try{

        for(int count=0; count<2; count++){
            System.out.println(name+ ":" +count);
            Thread.sleep(3000);
        }
       }

       catch(InterruptedException ex){

           System.out.println(name + "interrupted");

       }
       System.out.println(name + "exiting");

       }

    public static void main(String[] args) {
        BusinessAlive a1 = new BusinessAlive("Meeting Deadlines");
        BusinessAlive a2 = new BusinessAlive("Schedule Variance");
        BusinessAlive a3 = new BusinessAlive("Effort Variance");

        System.out.println("Frist task is alive:" +a1.objTh.isAlive());
        System.out.println("Second task is alive:" +a2.objTh.isAlive());
        System.out.println("Third task is alive:" +a3.objTh.isAlive());

        System.out.println("\ni am now free and go to holiday now" + "All task is over and exting\n");

        try {
        a1.objTh.join();
        a2.objTh.join();
        a3.objTh.join();
        }

        catch(InterruptedException ex){
            System.out.println("The End");
        }

        System.out.println("Frist task is alive:" +a1.objTh.isAlive());
        System.out.println("Second task is alive:" +a2.objTh.isAlive());
        System.out.println("Third task is alive:" +a3.objTh.isAlive());

        System.out.println("All tasks is over and exiting");

    }
    }


